<?php
class M_school_years extends CI_Model {
	
	private $__table = 'school_years';
	
	public function get_all_school_year($id=FALSE)
	{
		if($id == FALSE){
			$query = $this->db->get($this->__table);
		}else{
			$query = $this->db->where('id',$id)->get($this->__table);
		}
		
		return $query->num_rows() >= 1 ? $query->result() : FALSE;
	}
	
	/*
		Get Set School Year
	*/
	public function get_set_school_year()
	{
		
		$query = $this->db->where('is_set','yes')->get($this->__table);
		
		return $query->num_rows() >= 1 ? $query->result() : FALSE;
	}
	
	public function get_current_sy_format()
	{
		$data = $this->get_set_school_year();
		if(!empty($data))
		{
			foreach($data as $sy)
			{
				$date = $sy->sy_from.' - '.$sy->sy_to;
				break;
			}
			return $date;
		}else{
			return NULL;
		}
	}
	
	/*
		query to count all school years for pagnation
	*/	
	public function count_school_year()
	{
		return $this->db->count_all($this->__table);
	}
	
	/*
		query to fetch all school year for pagnation
	*/	
	public function fetch_school_year($limit, $start)
	{
        $this->db->limit($limit, $start);
        $query = $this->db->select(array('id','sy_from','sy_to','is_set'))->get($this->__table);
		return $query->num_rows() >= 1 ? $query->result() : FALSE;
	}
	
	public function get_id_of_current_sy()
	{
		$query = $this->db->where('is_set','yes')->select('id')->get($this->__table);
		if($query->num_rows () > 0 ){
			$row = $query->row();
			return $row->id;
		}		
	}
	
}
?>